package com.jiahe.blog.common.handler;

import com.alibaba.fastjson.JSON;
import com.jiahe.blog.model.response.BlogResponse;
import com.jiahe.blog.utils.ServletUtils;
import com.jiahe.blog.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Component
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
        String msg = StringUtils.format("注销成功");
        log.info(msg);
        ServletUtils.renderString(response, JSON.toJSONString(BlogResponse.success(msg,null)));
    }
}
